package com.cs.service.impl;

import com.cs.dto.MalfunctionDto;
import com.cs.dto.MalfunctionOptionsDto;
import com.cs.mapper.MalfunctionOptionsMapper;
import com.cs.entity.Malfunction;
import com.cs.mapper.MalfunctionMapper;
import com.cs.service.MalfunctionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 故障 服务实现类
 * </p>
 *
 * @author qf
 * @since 2021-08-04
 */
@Service
public class MalfunctionServiceImpl extends ServiceImpl<MalfunctionMapper, Malfunction> implements MalfunctionService {

    @Autowired
    private MalfunctionMapper malfunctionMapper;
    @Autowired
    private MalfunctionOptionsMapper malfunctionOptionsMapper;

    @Override
    public List<MalfunctionDto> getSpecListById(Long modelId) {
        List<MalfunctionDto> list = null;
        //根据modelid查故障表id
        list = malfunctionMapper.getSpecListById(modelId);
        //遍历故障表集合
        if (list != null) {
            for (MalfunctionDto malfunctionDto : list) {
                //获取故障id
                Long malfId = malfunctionDto.getId();
                //根据故障id查故障字典表
                List<MalfunctionOptionsDto> dtoList = malfunctionOptionsMapper.getMalfunctionOptionDtoListByMalfId(malfId);
                //将故障详情写入故障dto中
                malfunctionDto.setOptionsList(dtoList);
            }
        }
        return list;
    }
}
